home *** CD-ROM | disk | FTP | other *** search
Wrap
//******************************************************************' //* *' //* TurboCAD for Windows *' //* Copyright (c) 1993 - 2004 *' //* International Microcomputer Software, Inc. *' //* (IMSI) *' //* All rights reserved. *' //* *' //******************************************************************' using System; using System.Windows.Forms; namespace TCCSharpTool { /// <summary> /// Summary description for Class1. /// </summary> public class SampleTool { const short NUM_TOOLS = 1; //Toggle this to test loading buttons from .Bmp/.Res const bool boolLoadFromBmp = false; public SampleTool() { // // TODO: Add constructor logic here // } public string Description { get { return "TurboCAD CSharp Tool"; } } public bool Run(object Tool) { MessageBox.Show ("Add your code here"); return false; } public int GetToolInfo(out object CommandNames, out object MenuCaptions, out object StatusPrompts, out object ToolTips, out object Enabled, out object WantsUpdates) { try { string[] SCommandNames = new string[NUM_TOOLS]; string[,] SMenuCaptions = new string[NUM_TOOLS,2]; string[] SStatusPrompts = new string[NUM_TOOLS]; string[] SToolTips = new string[NUM_TOOLS]; bool[] BEnabled = new bool[NUM_TOOLS]; bool[] BWantsUpdates = new bool[NUM_TOOLS]; int[] iIndex = {0,0}; SCommandNames[0] = "Bonus|SDK Programming|C# Tool"; SMenuCaptions.SetValue ("C# Tool",iIndex); iIndex[1] = 1; Array arTest = Array.CreateInstance (typeof(string),1,2); arTest.SetValue ("test 1", 0, 0); arTest.SetValue ("test 2", 0, 1); SMenuCaptions.SetValue ("Bonus",0,1); //SMenuCaptions[0, 1] = "Bonus"; SStatusPrompts[0] = "C# Tool prompt"; SToolTips[0] = "C# Tool tooltip"; BEnabled[0] = true; BWantsUpdates[0] = false; CommandNames = SCommandNames; MenuCaptions = SMenuCaptions; StatusPrompts = SStatusPrompts; ToolTips = SToolTips; Enabled = BEnabled; WantsUpdates = BWantsUpdates; return NUM_TOOLS; } catch(Exception e) { Console.WriteLine("An error occurred: '{0}'", e); throw; } } /// <summary> /// Public Function GetPicture(ByVal LargeImage As Boolean, ByVal MonoImage As Boolean) As Object /// </summary> public object GetPicture(bool LargeImage, bool MonoImage) { System.Drawing.Bitmap TheImage; TheImage = null; if (GetButtonPicture(LargeImage, MonoImage, ref TheImage ) == true) { ImageConverter imgConverter = new ImageConverter() ; return imgConverter.ImageToIpicture(TheImage); } return null; } public bool CopyBitmap(bool LargeImage, bool MonoImage) { return true; } public bool Initialize(object Tool) { return true; } public bool UpdateToolStatus(object Tool, bool Enabled, bool Checked) { return true; } private bool GetButtonPicture(bool LargeImage, bool MonoImage, ref System.Drawing.Bitmap theImage ) { string s, s1; bool bRet = false; //define correct path to the icons here' // ' copy of these bmp files are located in TCVBNETTool directory // 'There are two ways to load images: from .Bmp file(s) or from .RES resource. // 'In this demo, we control the loading by a private variable. // Dim img As System.Drawing.Image // Dim thisApp As System.Reflection.Assembly // Dim file As System.IO.Stream System.Reflection.Assembly thisApp; System.IO.Stream file; System.Drawing.Image img; if (boolLoadFromBmp == true) { if (LargeImage) { img = System.Drawing.Image.FromFile(s1); //'"LargeIcon.bmp") bRet = true; } else { img = System.Drawing.Image.FromFile(s); //'"SmallIcon.bmp") bRet = true; } } else { if (LargeImage) { thisApp = System.Reflection.Assembly.GetExecutingAssembly(); file = thisApp.GetManifestResourceStream("TCCSharpTool.LargeIcon.bmp"); img = System.Drawing.Image.FromStream(file); bRet = true; } else { thisApp = System.Reflection.Assembly.GetExecutingAssembly(); file = thisApp.GetManifestResourceStream("TCCSharpTool.SmallIcon.bmp"); img = System.Drawing.Image.FromStream(file); bRet = true; } } theImage = (System.Drawing.Bitmap)img; return bRet; } } public class ImageConverter : System.Windows.Forms.AxHost { public ImageConverter():base("59EE46BA-677D-4d20-BF10-8D8067CB8B33") { } public stdole.IPictureDisp ImageToIpicture(System.Drawing.Image image) { return (stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image); } public System.Drawing.Image IPictureToImage(stdole.StdPicture picture) { return ImageConverter.GetPictureFromIPicture(picture); } } }